package com.ocean.service.library.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ocean.dao.library.AdministratorDao;
import com.ocean.entity.library.Administrator;
import com.ocean.service.library.AdministratorService;
import com.ocean.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Project：SchoolManage
 * Package：com.ocean.service.library.impl
 * Author:zy
 * Time:2023/3/3
 */

@Service
public class AdministratorServiceImpl implements AdministratorService {
    @Autowired
    private AdministratorDao administratorDao;

    @Override
    public R save(Administrator administrator) {
        if (administratorDao.insert(administrator) > 0) {
            return R.ok();
        } else {
            return R.fail("插入管理员失败");
        }
    }

    @Override
    public R del(int id) {
        if (administratorDao.delete(id)>0) {
            return R.ok();
        }else {
            return R.fail("删除管理员失败");
        }
    }

    @Override
    public R update(Administrator administrator) {
        if (administratorDao.update(administrator)>0) {
            return R.ok();
        }else {
            return R.fail("更新管理员失败");
        }
    }

    @Override
    public R queryPage(int page, int size) {
        PageHelper.startPage(page, size);
        PageInfo<Administrator> pageInfo = new PageInfo<>(administratorDao.selectAll());
        return R.ok(pageInfo);
    }
}
